<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改规则要素清单')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-items-edit" th:object="${ruleElementsItems}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">归属机构：</label>
            <div class="col-sm-8">
                <select name="deptId" class="form-control" th:with="type=${@dept.selectDeptListByType('2')}"
                        disabled
                        required>
                    <option th:each="dept : ${type}" th:text="${dept.deptName}" th:value="${dept.deptId}"
                            th:field="*{deptId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">要素名称：</label>
            <div class="col-sm-8">
                <input name="elementsName" th:field="*{elementsName}" class="form-control" required maxlength="30"
                       type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label  is-required">要素类型：</label>
            <div class="col-sm-8">
                <select name="elementsType" class="form-control"
                        th:with="type=${@dict.getType('risk_variable_type')}" required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{elementsType}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label  is-required">是否枚举：</label>
            <div class="col-sm-8">
                <select name="isEnum" id="isEnum" class="form-control" onchange="enumerationOrNot(this.value)"
                        th:with="type=${@dict.getType('common_yes_no')}" required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{isEnum}"></option>
                </select>
            </div>
        </div>
        <div class="form-group" id="ev-div">
            <label class="col-sm-3 control-label is-required">枚举值编码：</label>
            <div class="col-sm-8">
                <div class="input-group" onclick="selectDictTree()">
                    <input class="form-control" type="text" th:field="*{enumValue}" name="enumValue" id="enumValue"
                           required
                           readonly>
                    <span class="input-group-addon input-sm"><i
                            class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group" id="en-div">
            <label class="col-sm-3 control-label  is-required">枚举值名称：</label>
            <div class="col-sm-8">
                <input name="enumName" id="enumName" th:field="*{enumName}" class="form-control" type="text" readonly
                       required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">要素单位：</label>
            <div class="col-sm-8">
                <input name="elementsUnit" class="form-control" type="text" maxlength="3" th:field="*{elementsUnit}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control" maxlength="200">[[*{remark}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "rule/items";
    $("#form-items-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-items-edit').serialize());
        }
    }
    var isEnum = [[${ruleElementsItems.isEnum}]];
    $(function () {
        enumerationOrNot(isEnum);
    });
    /**
     * 是否枚举事件
     */
    function enumerationOrNot(val) {
        if (val == "T") {
            document.getElementById("ev-div").style.display = "";
            document.getElementById("en-div").style.display = "";
        } else {
            document.getElementById("ev-div").style.display = "none";
            document.getElementById("en-div").style.display = "none";
        }
    }

    // 选择字典处理函数
    function selectDictTree() {
        var dictType = "-";
        var url = ctx + "system/dict/selectDictTree/1/" + dictType;
        var options = {
            title: '选择字典类型',
            width: "380",
            url: url,
            callBack: doDictSubmit
        };
        $.modal.openOptions(options);
    }

    function doDictSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        var dictType = body.find('#dictType').val();
        var dictName = body.find('#dictName').val();
        $.modal.close(index);
        $('#enumValue').val(dictType);
        $('#enumName').val(dictName);
    }
</script>
</body>
</html>